<template>

  <view class="instrument">
    <scroll-view @scrolltolower="scrolltolower" class="scrollView box" refresher-background="rgba(0, 0, 0, 0)" refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="100" @refresherrefresh="onRefresh" @refresherrestore="onRestore" :style="{'height':  'calc('+ screenHeight  +'px' +' ' + '-' +' ' + excessHeight +'rpx)'}" scroll-y="true">
      <u-waterfall v-model="list" ref="uWaterfall" add-time="0">
        <template v-slot:left="{leftList}">
          <view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="toDetail(item)">
            <!-- <u-lazy-load threshold="0" border-radius="10" :image="item.main_image" :index="index" class="picture"></u-lazy-load> -->
            <image class="picture" :src="item.main_image" mode="scaleToFill" />
            <view class="demo-title">
              {{item.title}}
            </view>
            <view class="demo-tag-address">
              <view class="demo-tag">
                <view class="pic">
                  <image class="img-tag" src="/static/images/indexpage/topic-icon.png"></image>
                </view>
                <view class="price"> {{item.is_adv!=1?item.label:'广告'}}</view>
              </view>
            </view>
            <view class="demo-price" v-if="item.is_adv!=1">
              <view class="pic">
                ¥
              </view>
              <view class="price"> {{item.price}}</view>
            </view>
            <view class="demo-avatar" v-if="item.is_adv!=1">
              <view class="pic">
                <image class="point-tag" @click.stop="toUserDetail(item)" :src="item.avatar"></image>
              </view>
              <view class="price" @click.stop="toUserDetail(item)"> {{item.nickname}}</view>
            </view>
          </view>
        </template>
        <template v-slot:right="{rightList}">
          <view class="demo-warter demo-warter1" v-for="(item, index) in rightList" :key="index" @click="toDetail(item)">
            <image class="picture" :src="item.main_image" mode="scaleToFill" />
            <!-- <u-lazy-load threshold="0" border-radius="10" :image="item.main_image" :index="index" class="picture"></u-lazy-load> -->
            <view class="demo-title">
              {{item.title}}
            </view>
            <view class="demo-tag-address">
              <view class="demo-tag">
                <view class="pic">
                  <image class="img-tag" src="/static/images/indexpage/topic-icon.png"></image>
                </view>
                <view class="price"> {{item.is_adv!=1?item.label:'广告'}}</view>
              </view>
            </view>
            <view class="demo-price" v-if="item.is_adv!=1">
              <view class="pic">
                ¥
              </view>
              <view class="price"> {{item.price}}</view>
            </view>
            <view class="demo-avatar" v-if="item.is_adv!=1">
              <view class="pic">
                <image class="point-tag" @click.stop="toUserDetail(item)" :src="item.avatar"></image>
              </view>
              <view class="price" @click.stop="toUserDetail(item)"> {{item.nickname}}</view>
            </view>
          </view>
        </template>
      </u-waterfall>
      <view class="nodata-st" v-if="form.page==form.last_page"> ------没有更多数据了------</view>
      <view class="nodata-st" v-if="list.length ==0"> ------暂无数据------</view>
      <view style="height:24rpx;"></view>
    </scroll-view>

  </view>
</template>

<script>
import api from '@/api/index.js';
export default {
  name: "x-instrument",
  props: {
    screenHeight: {
      type: Number,
      default: uni.getStorageSync('screenHeight') - uni.getStorageSync('safeAreaBottom')
    },
    excessHeight: {
      type: Number,
      default: 0
    },
    query: {
      type: Object,
      default() {
        return {}
      }
    },

  },
  data() {
    return {
      triggered: true,
      list: [],
      form: {
        page: 1,
        page_size: 10,
        last_page: 0,
      },
      isShowList: false
    };
  },
  mounted() {
    // this.init()
    console.log(this.query)
    this._freshing = false;
    setTimeout(() => {
      this.triggered = true;
    }, 1000)
  },

  methods: {
    init() {

      this.$refs.uWaterfall.clear();
      // this.isShowList = false
      this.list = []
      this.form.page = 1;
      this.form.last_page = 0;
      this.getpage()
    },
    getpage() {

      console.log('查询条件')
      console.log(this.query)
      api.base.getTrends({ ...this.form, ...this.query }).then(res => {
        if (res.code == 1) {
          console.log('请求进来了')
          // this.isShowList = false

          this.list = this.form.page === 1 ? res.data.data : this.list.concat(res.data.data);
          this.form.last_page = res.data.last_page;
          console.log(this.list)



        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      });
    },
    onRefresh() {
      if (this._freshing) return;
      this._freshing = true;
      // this.init()
      this.$emit('initPage');
      setTimeout(() => {
        this.triggered = false;
        this._freshing = false;
      }, 1000)
    },
    onRestore() {
      this.triggered = 'restore'; // 需要重置
      console.log("onRestore");
    },
    scrolltolower() {
      if (this.form.page < this.form.last_page) {
        this.form.page += 1;
        this.getpage();
      }
    },
    toDetail(item) {
      //  跳转广告 或详情
      if (item.is_adv == 1) {
        uni.navigateTo({
          url: `/pages/componets/instrument/advertisement/index?id=` + item.id
        });
      } else {
        uni.navigateTo({
          url: `/pages/componets/instrument/instrumentDetail/index?types=` + this.query.types + '&id=' + item.id
        });
      }
    },
    toUserDetail(item) {
      if (uni.getStorageSync('userinfo').user_id == item.user_id) {
        uni.switchTab({
          url: '/pages/my/my'
        })
      } else {
        uni.navigateTo({
          url: `/pages/otherPeople/index?user_id=` + item.user_id
        });
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.instrument {
  .demo-warter {
    // background: yellowgreen;
    border-radius: 8px;
    margin: 0rpx 5rpx 20rpx 0rpx;
    padding: 0rpx 8rpx 8rpx 32rpx;
    position: relative;
    .picture {
      width: 315rpx;
      // height: 315rpx;
    }
  }
  .demo-warter1 {
    margin: 0rpx 5rpx 20rpx 5rpx;
    padding: 0rpx 32rpx 8rpx 8rpx;
  }

  .u-close {
    position: absolute;
    top: 32rpx;
    right: 32rpx;
  }

  .demo-image {
    width: 100%;
    border-radius: 4px;
  }

  .demo-title {
    font-size: 28rpx;
    margin-top: 5px;
    font-size: 28rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: bold;
    color: #333333;

    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .demo-tag-address {
    margin: 16rpx 6rpx 6rpx 6rpx;
    width: calc(100% - 32rpx);
    height: 30rpx;
    display: flex;
    // justify-content: space-between;
    .demo-tag {
      padding-left: 6rpx;
      padding-right: 6rpx;
      display: flex;
      // width: 168rpx;
      background: rgba(109, 12, 247, 0.1);
      border-radius: 44rpx 44rpx 44rpx 44rpx;
      opacity: 1;
      justify-content: center;
      align-items: center;
      .pic {
        width: 20rpx;
        height: 20rpx;
        display: flex;
        justify-content: center;
        align-content: center;
        .img-tag {
          width: 20rpx;
          height: 20rpx;
        }
      }
      .price {
        display: flex;
        justify-content: center;
        align-content: center;
        padding-left: 8rpx;
        font-size: 16rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 500;
        color: #6d0cf7;
        // height: 30rpx;
        // line-height: 3rpx;
      }
    }
    .demo-address {
      padding-left: 16rpx;
      padding-right: 16rpx;
      background: #f3f3f3;
      .price {
        color: #333333;
      }
      .pic {
        height: 47rpx;
        line-height: 47rpx;
        width: 24rpx;
        height: 24rpx;
        // border-radius: 100rpx;
        // background: #6d0cf7;
        font-size: 24rpx;
        color: #ffffff;
        display: flex;
        justify-content: center;
        align-content: center;
        .img-tag {
          width: 24rpx;
          height: 24rpx;
        }
      }
    }
  }

  .demo-tag-owner {
    color: #ffffff;
    display: flex;
    align-items: center;
    padding: 4rpx 14rpx;
    border-radius: 50rpx;
    font-size: 20rpx;
    line-height: 1;
  }

  .demo-tag-text {
    border: 1px solid #fff;
    margin-left: 10px;
    border-radius: 50rpx;
    line-height: 1;
    padding: 4rpx 14rpx;
    display: flex;
    align-items: center;
    border-radius: 50rpx;
    font-size: 20rpx;
  }

  .demo-price {
    font-family: HarmonyOS Sans-Bold, HarmonyOS Sans;
    font-weight: bold;
    color: #ff2544;
    height: 44rpx;
    line-height: 44rpx;
    padding-top: 6rpx;
    margin-bottom: 16rpx;
    .pic {
      float: left;
      font-size: 24rpx;
      line-height: 55rpx;
      .point-tag {
        width: 40rpx;
        height: 40rpx;
        border-radius: 7694rpx 7694rpx 7694rpx 7694rpx;
      }
    }
    .price {
      float: left;
      padding-left: 5rpx;
      font-size: 40rpx;
    }
  }
  .demo-avatar {
    height: 44rpx;
    line-height: 44rpx;
    padding-top: 6rpx;
    margin-bottom: 16rpx;
    .pic {
      display: flex;
      justify-content: center;
      align-items: center;
      float: left;
      width: 40rpx;
      height: 40rpx;
      .point-tag {
        width: 40rpx;
        height: 40rpx;
        border-radius: 7694rpx 7694rpx 7694rpx 7694rpx;
      }
    }
    .price {
      height: 44rpx;
      line-height: 44rpx;
      padding-left: 15rpx;
      padding-right: 15rpx;
      font-size: 24rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 500;
      color: #999999;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
    }
  }
  .demo-shop {
    font-size: 22rpx;
    margin-top: 5px;
  }
  .on-things {
    margin-top: 100rpx;
    font-size: 34rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 600;
    color: #333333;
    text-align: center;
  }
}
</style>